<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>用户登录</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<script type="application/x-javascript">
			addEventListener("load", function() {
				setTimeout(hideURLbar, 0);
			}, false);
			function hideURLbar() {
				window.scrollTo(0, 1);
			}
		</script>

		<link href="css/style.css" rel='stylesheet' type='text/css' />
		<script src="js/jquery.min.js"></script>
	</head>
	<body onload="clearS()">
		<script>
			function clearS(){
				$.ajax({
						url:"http://gyp.meidongya.cn/public/logout",
						type: 'post',
						dataType :'json',
						async:true,
						success : function(data) {
							console.log('clearS');
						},
					});
			}
			function encryptPassword(){
				var username = $("#username").val();
				var password = $("#password").val();
				if(username == null || username == ''){
					console.log(1)
					$('#error').text('请输入用户名');
				}else if(password == null || password == ''){
					console.log(2)
					$('#error').text('请输入密码');
				}else{
					console.log(3)
					$.ajax({
						url:"http://gyp.meidongya.cn/public/login",
						type: 'post',
						dataType :'json',
						async:true,
						data:{'username':username,'password':password},
						success : function(data) {
							console.log(data);
							if(data != 0){
								console.log(4)
								$(location).attr('href', 'main.php');						
							}else{
								console.log(5)
								$('#error').text("失败");	
							}
						},
						error:function(msg){
							console.log(6)
							$('#error').text('登录失败');
						}
					});					
				}	
				return false;
		    }

			/*$(document).ready(
				function(c){
					$('#login').on('click',function(c){
						var username = $("#username").val();
						var password = $("#password").val();
						if(username == null || username == ''){
							$('#error').text('请输入用户名');
						}else if(password == null || password == ''){
							$('#error').text('请输入密码');
						}else{
							$.ajax({
								url:"http://gyp.meidongya.cn/public/login",
								type: 'post',
								dataType :'json',
								async:true,
								data:{'username':username,'password':password},
								success : function(data) {
									// console.log(data);
									if(data != 0){
										$(location).attr('href', 'main.php');						
									}else{
										$('#error').text("失败");	
									}
								},
								error:function(msg){
									$('#error').text('登录失败');
								}
							});
							
						}
						
					});
				}	
			);*/
		</script>
		<h1>光伏微网能量管理系统</h1>
		<div class="login-form">
			<!-- <div class="close"> </div> -->
			<div class="head-info">
				<label class="lbl-1"></label>
				<label class="lbl-2"></label>
				<label class="lbl-3"></label>
			</div>
			<div class="clear">
			</div>
			<!-- 
			<div class="avtar">
				<img src="images/avtar.png" />
			</div>
			 -->
			 <div id = "error" style="color:red;"></div>
			<form onsubmit="return encryptPassword()">
				<input type="text" class="text" id = "username">
				<div class="key">
					<input type="password" id = "password">
				</div>
				<input type="submit" value="登陆">
			</form>
		</div>
		<div class="copy-rights">
			<p>Copyright &copy;小郭童鞋专用^_^</p>
		</div>

	</body>
</html>